//
//  DailyDietViewCell.m
//  SHHCPhone
//
//  Created by gfsh on 14-7-3.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "DailyDietViewCell.h"
#import "DailyDietInfo.h"

@implementation DailyDietViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.frame = CGRectMake(0, 0, self.frame.size.width, 50);
        self.backgroundColor = [UIColor clearColor];
        
        _bg = [[UIImageView alloc]initWithFrame:CGRectMake(48, 0, self.frame.size.width-48, 50)];
        _bg.userInteractionEnabled = YES;
        [self addSubview:_bg];
        
        _mealBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_mealBtn.layer setMasksToBounds:YES];
        [_mealBtn.layer setCornerRadius:9];
        _mealBtn.frame = CGRectMake(0, 9, 45, 19);
        _mealBtn.backgroundColor = GET_COLOR(@"f6f6f6");
        [_mealBtn setTitleColor:GET_COLOR(@"3e3e3e") forState:UIControlStateNormal];
        [_mealBtn setTitleColor:GET_COLOR(@"ffffff") forState:UIControlStateSelected];
        _mealBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        _mealBtn.hidden = YES;
//        [_mealBtn addTarget:self action:@selector(mealBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        _mealPic = [[UIImageView alloc]initWithFrame:CGRectMake(60, 7, 36, 36)];
        _mealPic.backgroundColor = NORMAL_IMAGE_BGCOLOR;//[UIColor lightGrayColor];
        
        _foodLab = [[UILabel alloc]initWithFrame:CGRectMake(_mealPic.frame.origin.x+_mealPic.frame.size.width+7, 7, self.frame.size.width-93-35-18-10, (self.frame.size.height-14)/2)];
        _foodLab.backgroundColor = [UIColor clearColor];
        _foodLab.textAlignment = NSTextAlignmentLeft;
        _foodLab.textColor = GET_COLOR(@"3e3e3e");
        _foodLab.font = [UIFont systemFontOfSize:13];
        
        _detailLab = [[UILabel alloc]initWithFrame:CGRectMake(_foodLab.frame.origin.x, _foodLab.frame.origin.y+_foodLab.frame.size.height+3, _foodLab.frame.size.width, (self.frame.size.height-14)/2)];
        _detailLab.backgroundColor = [UIColor clearColor];
        _detailLab.textAlignment = NSTextAlignmentLeft;
        _detailLab.textColor = GET_COLOR(@"626262");
        _detailLab.font = [UIFont systemFontOfSize:12];
        
        _refreshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _refreshBtn.frame = CGRectMake(_detailLab.frame.origin.x+_detailLab.frame.size.width-13, 0, 50, self.frame.size.height);
        _refreshBtn.contentEdgeInsets = UIEdgeInsetsMake(self.frame.size.height/2-27/2, 50/2-27/2, self.frame.size.height/2-27/2, 50/2-27/2);
        [_refreshBtn setImage:[UIImage imageNamed:@"每日食谱-刷新按钮"] forState:UIControlStateNormal];
        [_refreshBtn setImage:[UIImage imageNamed:@"每日食谱-刷新按钮-点击"] forState:UIControlStateHighlighted];
        [_refreshBtn sizeToFit];
        [_refreshBtn addTarget:self action:@selector(refreshClick) forControlEvents:UIControlEventTouchUpInside];
        
        _showOther = [[UILabel alloc]initWithFrame:CGRectMake(50, 0, self.frame.size.width-50, self.frame.size.height)];
        _showOther.backgroundColor = [UIColor clearColor];
        _showOther.textAlignment = NSTextAlignmentCenter;
        _showOther.textColor = GET_COLOR(@"868686");
        _showOther.font = [UIFont systemFontOfSize:12];
        _showOther.text = @"查看其他菜品";
        UIImageView *arrowIV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"每日食谱-下拉查看icon"]];
        arrowIV.frame = CGRectMake(_showOther.frame.size.width/2-50, _showOther.frame.size.height/2-11/2, 11, 11);
        arrowIV.userInteractionEnabled = YES;
        [_showOther addSubview:arrowIV];
        _showOther.hidden = YES;
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(52, self.frame.size.height-1, self.frame.size.width-52, 1)];
        line.backgroundColor = GET_COLOR(@"f6f6f6");

        self.contentView.backgroundColor = [UIColor clearColor];
        
        [self addSubview:line];
        
        [self addSubview:_mealBtn];
        [self addSubview:_mealPic];
        [self addSubview:_foodLab];
        [self addSubview:_detailLab];
        [self addSubview:_refreshBtn];
        [self addSubview:_showOther];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectOne)];
        [self addGestureRecognizer:tap];

    }
    return self;
}

- (void)hideShowOther:(BOOL)show
{
    _showOther.hidden = show;
    _mealPic.hidden = !show;
    _foodLab.hidden = !show;
    _detailLab.hidden = !show;
    _refreshBtn.hidden = !show;
}

- (void)refreshClick
{
    if ([self.delegate respondsToSelector:@selector(refreshBtnClick:)]) {
        [self.delegate performSelectorInBackground:@selector(refreshBtnClick:) withObject:self];
    }
}

- (void)mealBtnClick:(UIButton*)btn
{
    if (!btn.selected) {
        if ([self.delegate respondsToSelector:@selector(cellMealBtnClick:)]) {
            [self.delegate performSelectorInBackground:@selector(cellMealBtnClick:) withObject:self];
        }
    }
}

- (void)selectOne
{
    if ([self.delegate respondsToSelector:@selector(cellItemSelected:)]) {
        [self.delegate performSelectorInBackground:@selector(cellItemSelected:) withObject:self];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
